package com.lzw.breezeNovel.webApp.controller.novel;

import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import com.lzw.breezeNovel.model.entity.query.Search;
import com.lzw.breezeNovel.webApp.service.novel.BookService;
import com.lzw.breezeNovel.webApp.vo.novel.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.controller
 * @date 2025/3/2
 * @description 小说控制类
 */
@RestController
@RequestMapping("/app/book")
@SuppressWarnings("all")
public class BookController {

    /**
     * 注入Service
     */
    @Autowired
    private BookService bookService;

    /**
     * 获取限时免费的小说
     */
    @GetMapping("/getFreeBooks")
    public Result<List<BookVo>> getFreeBooks(){
       List<BookVo> bookVos =  bookService.getFreeBooks();
       return Result.ok(bookVos);
    }

    /**
     * 获取最新的书籍
     */
    @GetMapping("/getNewBooks")
    public Result<List<BookVo>> getNewBooks(){
       List<BookVo> bookVos =  bookService.getNewBooks();
       return Result.ok(bookVos);
    }

    /**
     * 分页查询最新的书籍
     */
    @GetMapping("/getNewBooksByPage")
    public Result<PaginationResultQuery<BookVo>> getNewBooksByPage(@RequestParam Integer page, @RequestParam  Integer pageSize){
        PaginationResultQuery<BookVo> bookVos =  bookService.getNewBooksByPage(page,pageSize);
       return Result.ok(bookVos);
    }

    /**
     * 根据小说的类型获取数据
     */
    @GetMapping("/getBooksByType")
    public Result<List<BookVo>> getBooksByType(@RequestParam String type){
       List<BookVo> bookVos =  bookService.getBooksByType(type);
       return Result.ok(bookVos);
    }

    /**
     * 根据小说类型分页获取数据
     */
    @GetMapping("/getBooksByTypeByPage")
    public Result<PaginationResultQuery<BookVo>> getBooksByTypeByPage(@RequestParam String type,@RequestParam Integer page, @RequestParam  Integer pageSize){
       PaginationResultQuery<BookVo> bookVos =  bookService.getBooksByTypeByPage(type,page,pageSize);
       return Result.ok(bookVos);
    }

    /**
     * 根据书籍id获取书籍
     */
    @GetMapping("/getBookByBookId")
    public Result<BookVo> getBookById(@RequestParam Long bookId){
       BookVo bookVo =  bookService.getBookById(bookId);
       return Result.ok(bookVo);
    }

    /**
     * 模糊查询书籍
     */
    @PostMapping("/searchBook")
    public Result<PaginationResultQuery<BookVo>> searchBook(@RequestBody Search search){
       PaginationResultQuery<BookVo> bookVos =  bookService.searchBook(search);
       return Result.ok(bookVos);
    }


}
